package com.lagou.edu.vo;

import java.io.Serializable;

public class Result<T> implements Serializable {

    private T data;

    private int code;

    private String msg;

    public static final int DEFAULT_SUCCESS_CODE = 200;

    public static final String DEFAULT_SUCCESS_MESSAGE = "ok";

    public static final int DEFAULT_FAILURE_CODE = 500;

    public static final String DEFAULT_FAILURE_MESSAGE = "fail";


    public Result(T data, int code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public static <T> Result<T> success(T data){
        Result result=new Result();
        result.setCode(DEFAULT_SUCCESS_CODE);
        result.setMsg(DEFAULT_SUCCESS_MESSAGE);
        result.setData(data);
        return result;

    }
    public static <T> Result<T> fail(String msg){
        Result result=new Result();
        result.setCode(DEFAULT_FAILURE_CODE);
        result.setMsg(msg);
        return result;

    }

    public Result() {
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
